Skip to content

Migrate away from deprecated ioutil#490

Open
sebrandon1 wants to merge 1 commit intoopenshift:mainfrom
sebrandon1:ioutil_deprecation
Open

Migrate away from deprecated ioutil#490
sebrandon1 wants to merge 1 commit intoopenshift:mainfrom
sebrandon1:ioutil_deprecation

Conversation

@sebrandon1
Copy link
Copy Markdown
Member

@sebrandon1 sebrandon1 commented Nov 24, 2025

ioutil has been deprecated since Go 1.16: https://go.dev/doc/go1.16#ioutil

Tracking issue: redhat-best-practices-for-k8s/telco-bot#52

Migration from ioutil to os package:

File and directory operations:

  • Replaced all instances of ioutil.ReadFile, ioutil.WriteFile, and ioutil.ReadDir with os.ReadFile, os.WriteFile, and os.ReadDir respectively throughout the codebase, including files like cfg.go, scmauths.go, sshkey.go, common.go, and their associated test files. [1] [2] [3] [4] [5] [6] [7] [8] [9]

  • Updated all usages of ioutil.TempFile and ioutil.TempDir to os.CreateTemp and os.MkdirTemp respectively, ensuring temporary files and directories are created using the recommended APIs. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]

Imports and cleanup:

These changes ensure the project is compatible with newer Go versions and avoids deprecated functionality.

Summary by CodeRabbit

  • Refactor
    • Replaced deprecated file and temp helpers with modern Go stdlib equivalents across the builder and test suites (file read/write and temp file/dir operations). No behavioral or public API changes; functionality and error handling preserved.

@openshift-bot
Copy link
Copy Markdown
Contributor

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

@openshift-ci openshift-ci bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 17, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 88da8657-aea9-4236-9e33-0036a8278796

📥 Commits

Reviewing files that changed from the base of the PR and between adcb7ed and e6c9462.

📒 Files selected for processing (20)
  • pkg/build/builder/cmd/dockercfg/cfg.go
  • pkg/build/builder/cmd/dockercfg/cfg_test.go
  • pkg/build/builder/cmd/scmauth/cacert.go
  • pkg/build/builder/cmd/scmauth/password.go
  • pkg/build/builder/cmd/scmauth/scmauth_test.go
  • pkg/build/builder/cmd/scmauth/scmauths.go
  • pkg/build/builder/cmd/scmauth/scmauths_test.go
  • pkg/build/builder/cmd/scmauth/sshkey.go
  • pkg/build/builder/cmd/scmauth/sshkey_test.go
  • pkg/build/builder/cmd/scmauth/util.go
  • pkg/build/builder/common.go
  • pkg/build/builder/common_test.go
  • pkg/build/builder/daemonless.go
  • pkg/build/builder/daemonless_test.go
  • pkg/build/builder/docker_test.go
  • pkg/build/builder/dockerutil_test.go
  • pkg/build/builder/source.go
  • pkg/build/builder/source_test.go
  • pkg/build/builder/sti.go
  • pkg/build/builder/util_linux.go
✅ Files skipped from review due to trivial changes (19)
  • pkg/build/builder/cmd/dockercfg/cfg_test.go
  • pkg/build/builder/util_linux.go
  • pkg/build/builder/sti.go
  • pkg/build/builder/cmd/dockercfg/cfg.go
  • pkg/build/builder/cmd/scmauth/sshkey_test.go
  • pkg/build/builder/dockerutil_test.go
  • pkg/build/builder/cmd/scmauth/sshkey.go
  • pkg/build/builder/cmd/scmauth/util.go
  • pkg/build/builder/common_test.go
  • pkg/build/builder/cmd/scmauth/scmauths_test.go
  • pkg/build/builder/common.go
  • pkg/build/builder/cmd/scmauth/scmauth_test.go
  • pkg/build/builder/daemonless.go
  • pkg/build/builder/source.go
  • pkg/build/builder/cmd/scmauth/cacert.go
  • pkg/build/builder/cmd/scmauth/password.go
  • pkg/build/builder/daemonless_test.go
  • pkg/build/builder/docker_test.go
  • pkg/build/builder/source_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/build/builder/cmd/scmauth/scmauths.go

Walkthrough

This PR replaces deprecated io/ioutil usage across the build package by switching to os package equivalents (ReadFile, WriteFile, CreateTemp, MkdirTemp, ReadDir), preserving existing control flow and error handling.

Changes

Cohort / File(s) Summary
SCM Auth package
pkg/build/builder/cmd/scmauth/cacert.go, pkg/build/builder/cmd/scmauth/password.go, pkg/build/builder/cmd/scmauth/scmauths.go, pkg/build/builder/cmd/scmauth/sshkey.go, pkg/build/builder/cmd/scmauth/util.go
Replaced ioutil helpers with os equivalents (TempFileCreateTemp, TempDirMkdirTemp, ReadDiros.ReadDir, WriteFileos.WriteFile). Adjusted scmauths to use []os.DirEntry where applicable; removed io/ioutil imports.
SCM Auth tests
pkg/build/builder/cmd/scmauth/scmauth_test.go, pkg/build/builder/cmd/scmauth/scmauths_test.go, pkg/build/builder/cmd/scmauth/sshkey_test.go
Tests updated to use os.MkdirTemp, os.CreateTemp, os.ReadFile, os.WriteFile, and os.ReadDir; removed io/ioutil imports.
Docker config
pkg/build/builder/cmd/dockercfg/cfg.go, pkg/build/builder/cmd/dockercfg/cfg_test.go
Switched ioutil.ReadFileos.ReadFile and ioutil.TempDiros.MkdirTemp in code and tests; removed io/ioutil imports.
Builder core logic
pkg/build/builder/common.go, pkg/build/builder/daemonless.go, pkg/build/builder/source.go, pkg/build/builder/sti.go, pkg/build/builder/util_linux.go
Replaced file I/O and temp helpers (ReadFile/WriteFile/TempFile/TempDir) with os equivalents; imports updated, control flow unchanged.
Builder tests
pkg/build/builder/common_test.go, pkg/build/builder/daemonless_test.go, pkg/build/builder/docker_test.go, pkg/build/builder/dockerutil_test.go, pkg/build/builder/source_test.go
Test files updated to use os equivalents for temp dirs/files, reads/writes, and directory reads; removed io/ioutil imports.
Other
pkg/build/builder/cmd/dockercfg/..., pkg/build/builder/...
Small, consistent replacements of deprecated io/ioutil usage across additional build-package files; behavior preserved.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 9 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.13% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (9 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main objective: migrating the codebase away from the deprecated ioutil package to use os equivalents instead.
Stable And Deterministic Test Names ✅ Passed PR updates internal test implementations to use os package functions instead of deprecated ioutil, maintaining test stability with no changes to test names or signatures.
Test Structure And Quality ✅ Passed The custom check for Ginkgo test code quality is not applicable to this PR, which uses standard Go testing package without any Ginkgo dependencies or patterns.
Microshift Test Compatibility ✅ Passed PR refactors deprecated ioutil calls to os package in existing unit tests only, no new Ginkgo e2e tests added.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No Ginkgo test patterns (It, Describe, Context, When) found in pkg/build/builder test files.
Topology-Aware Scheduling Compatibility ✅ Passed PR modernizes Go package imports by migrating from deprecated ioutil to standard os package with no deployment manifests or scheduling constraints introduced.
Ote Binary Stdout Contract ✅ Passed The PR only replaces deprecated ioutil functions with os package equivalents, which are pure filesystem operations that do not affect logging or stdout behavior. The main binary entry point already has logging properly configured to os.Stderr. No new logging statements, stdout writes, or logging configuration changes are introduced.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed This PR only refactors deprecated io/ioutil functions to os equivalents in existing code; no new Ginkgo e2e tests are added.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 17, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sebrandon1
Once this PR has been reviewed and has the lgtm label, please assign prabhapa for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/build/builder/cmd/scmauth/scmauths.go (1)

55-60: ⚠️ Potential issue | 🔴 Critical

os.ReadDir return type mismatches present signature (build break).

os.ReadDir returns []os.DirEntry, but present at line 23 accepts []os.FileInfo. The calls at line 60 (and line 40 in scmauths_test.go) will not compile.

Change the present signature from []os.FileInfo to []os.DirEntry—the function only calls Name(), which exists on both types.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/build/builder/cmd/scmauth/scmauths.go` around lines 55 - 60, The build
breaks because present currently accepts []os.FileInfo while os.ReadDir returns
[]os.DirEntry; update the present function signature (present) to accept
[]os.DirEntry instead of []os.FileInfo and adjust any callers (e.g., the
present(files) call and the test that passes directory listings) so they pass
the DirEntry slice; no other logic changes are needed since present only calls
Name() which exists on both types.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@pkg/build/builder/cmd/scmauth/scmauths.go`:
- Around line 55-60: The build breaks because present currently accepts
[]os.FileInfo while os.ReadDir returns []os.DirEntry; update the present
function signature (present) to accept []os.DirEntry instead of []os.FileInfo
and adjust any callers (e.g., the present(files) call and the test that passes
directory listings) so they pass the DirEntry slice; no other logic changes are
needed since present only calls Name() which exists on both types.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ec876062-ca39-458a-8f62-f2fa2af5aeb7

📥 Commits

Reviewing files that changed from the base of the PR and between fcd4ce2 and adcb7ed.

📒 Files selected for processing (20)
  • pkg/build/builder/cmd/dockercfg/cfg.go
  • pkg/build/builder/cmd/dockercfg/cfg_test.go
  • pkg/build/builder/cmd/scmauth/cacert.go
  • pkg/build/builder/cmd/scmauth/password.go
  • pkg/build/builder/cmd/scmauth/scmauth_test.go
  • pkg/build/builder/cmd/scmauth/scmauths.go
  • pkg/build/builder/cmd/scmauth/scmauths_test.go
  • pkg/build/builder/cmd/scmauth/sshkey.go
  • pkg/build/builder/cmd/scmauth/sshkey_test.go
  • pkg/build/builder/cmd/scmauth/util.go
  • pkg/build/builder/common.go
  • pkg/build/builder/common_test.go
  • pkg/build/builder/daemonless.go
  • pkg/build/builder/daemonless_test.go
  • pkg/build/builder/docker_test.go
  • pkg/build/builder/dockerutil_test.go
  • pkg/build/builder/source.go
  • pkg/build/builder/source_test.go
  • pkg/build/builder/sti.go
  • pkg/build/builder/util_linux.go

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 17, 2026

@sebrandon1: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/security e6c9462 link false /test security

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants